//
//  HNRadioViewController.m
//  HappyNews
//
//  Created by baiping on 15/12/27.
//  Copyright © 2015年 bai wang. All rights reserved.
//

#import "HNRadioViewController.h"
// 精选
#import "ChoicenessViewController.h"
// 娱乐
#import "RecreationViewController.h"
// 军事
#import "WarViewController.h"
// 历史
#import "HistoryViewController.h"
// 搞笑
#import "FunnyViewController.h"
// 微剧
#import "TinyViewController.h"
// 精选的二级跳转
#import "HNChoicenessViewController.h"
// 娱乐的二级跳转
#import "HNRecreationViewController.h"
// 军事的二级跳转
#import "HNWarHeaderViewController.h"
// 历史的二级跳转
#import "HNHistoryHeaderViewController.h"

typedef NS_ENUM(NSUInteger, ButtonTag) {
    One = 200,
    Two,
    Three,
    Four,
    Five,
    Six
};
@interface HNRadioViewController ()<UIScrollViewDelegate,ChoicenessViewDelegate,RecreationHeaderDelegate,WarViewDelegate,HistoryViewDelegate>
// 原创
@property (nonatomic, strong) ChoicenessViewController *choicenessVC;
@property (nonatomic, strong) UIButton *choicenessButton;
@property (nonatomic, strong) HNChoicenessViewController *HNChoicenessVC;
// 娱乐
@property (nonatomic, strong) RecreationViewController *recreationVC;
@property (nonatomic, strong) UIButton *recreationButton;
// 军事
@property (nonatomic, strong) WarViewController *warVC;
@property (nonatomic, strong) UIButton *warButton;
// 历史
@property (nonatomic, strong) HistoryViewController *historyVC;
@property (nonatomic, strong) UIButton *historyButton;
// 搞笑
@property (nonatomic, strong) FunnyViewController *funnyVC;
@property (nonatomic, strong) UIButton *funnyButton;
// 微剧
@property (nonatomic, strong) TinyViewController *tinyVC;
@property (nonatomic, strong) UIButton *tinyButton;

// 主ScrollView
@property (nonatomic, strong) UIScrollView *mainScrollView;

@property (nonatomic, strong) NSArray *buttonArray;



@end

@implementation HNRadioViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     self.view.backgroundColor = [UIColor whiteColor];
    
    [self addVideoHeaderView];
    [self addMainScrollView];
    
        
}
- (void)addVideoHeaderView
{
    NSArray *array = @[@"原创",@"娱乐",@"军事",@"历史",@"搞笑",@"微剧"];
    for (int i = 0; i < 6; i++) {
        UIButton  *button = [UIButton buttonWithType:(UIButtonTypeSystem)];
        button.frame = CGRectMake(kScreenWidth / 6 * i + 0, 64, kScreenWidth / 6, 40);
        [button setTitle:array[i] forState:(UIControlStateNormal)];
        button.tag = 200 + i;
        [button setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.view addSubview:button];
    }
    _choicenessButton = [self.view viewWithTag:200];
    [_choicenessButton setTitleColor:[UIColor redColor] forState:(UIControlStateNormal)];
    [UIView animateWithDuration:0 animations:^{
        _mainScrollView.contentOffset = CGPointMake(0, 0);
    }];
    _recreationButton = [self.view viewWithTag:201];
    
    _warButton =   [self.view viewWithTag:202];
    
    _historyButton = [self.view viewWithTag:203];
    
    _funnyButton = [self.view viewWithTag:204];
    
    _tinyButton = [self.view viewWithTag:205];
    
    _buttonArray = @[_choicenessButton, _recreationButton, _warButton, _historyButton, _funnyButton, _tinyButton];
}
// 设置点击button的改变颜色  更改视图
- (void)buttonAction:(UIButton *)button
{
    NSInteger index = button.tag - 200;
    [self changeButtonsColor:index];
    [UIView animateWithDuration:0 animations:^{
        [_mainScrollView setContentOffset:CGPointMake(index * _mainScrollView.width, 0) animated:NO];
    }];
}
// 点击button的颜色方法
- (void)changeButtonsColor:(NSInteger)index {
    for (int i = 0; i < _buttonArray.count; i ++) {
        UIButton *button = _buttonArray[i];
        if (i != index) {
            [button setTitleColor:[UIColor grayColor] forState:(UIControlStateNormal)];
            button.titleLabel.font = [UIFont systemFontOfSize:14];
        } else {
            [button setTitleColor:[UIColor redColor] forState:(UIControlStateNormal)];
            
            [UIView animateWithDuration:1 animations:^{
                button.titleLabel.font = [UIFont systemFontOfSize:1];
            }];
            
            [UIView animateWithDuration:1 animations:^{
                button.titleLabel.font = [UIFont systemFontOfSize:19];
            }];
            
        }
    }
}
// 添加 主ScrollView 的 6 个 视图
- (void)addMainScrollView
{
    _mainScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 104, kScreenWidth, kScreenHeight - 104)];
    _mainScrollView.pagingEnabled = YES;
    _mainScrollView.contentSize = CGSizeMake(kScreenWidth * 6, _mainScrollView.frame.size.height);
    _mainScrollView.delegate = self;
    _mainScrollView.showsHorizontalScrollIndicator = NO;
    _mainScrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_mainScrollView];
    
    
    
    
    // 原创
    _choicenessVC = [[ChoicenessViewController alloc]init];
    _choicenessVC.view.frame = CGRectMake(0, 0, kScreenWidth, _mainScrollView.frame.size.height);
    _choicenessVC.delegate = self;
    [_mainScrollView addSubview:_choicenessVC.view];
    
    //娱乐
    _recreationVC = [[RecreationViewController alloc]init];
    _recreationVC.view.frame = CGRectMake(kScreenWidth, 0, kScreenWidth, _mainScrollView.frame.size.height);
    _recreationVC.delegate = self;
    [_mainScrollView addSubview:_recreationVC.view];
    
    // 军事
    _warVC = [[WarViewController alloc]init];
    _warVC.view.frame = CGRectMake(kScreenWidth * 2, 0, kScreenWidth, _mainScrollView.frame.size.height);
    _warVC.delegate = self;
    [_mainScrollView addSubview:_warVC.view];
  
    
    // 历史
    _historyVC = [[HistoryViewController alloc]init];
    _historyVC.view.frame = CGRectMake(kScreenWidth * 3, 0, kScreenWidth, _mainScrollView.frame.size.height);
    _historyVC.delegate = self;
    [_mainScrollView addSubview:_historyVC.view];
    
    // 搞笑
    _funnyVC = [[FunnyViewController alloc]init];
    _funnyVC.view.frame = CGRectMake(kScreenWidth * 4, 0, kScreenWidth, _mainScrollView.frame.size.height);
    [_mainScrollView addSubview:_funnyVC.view];
   
    
    // 微剧
    _tinyVC = [[TinyViewController alloc]init];
    _tinyVC.view.frame = CGRectMake(kScreenWidth * 5, 0, kScreenWidth, _mainScrollView.frame.size.height);
    [_mainScrollView addSubview:_tinyVC.view];
    
    
    
}
// 滑动MainScrollView 来控制button的颜色
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSInteger index = scrollView.contentOffset.x / _mainScrollView.width;
    [self changeButtonsColor:index];
}

// 原创   实现代理方法
- (void)addNavigationController:(NSString *)guid
{
    _HNChoicenessVC = [[HNChoicenessViewController alloc]init];
    
    _HNChoicenessVC.guid = guid;
    
    [self.navigationController pushViewController:_HNChoicenessVC animated:YES];
    
}
//  娱乐    实现代理方法
- (void)addRecreationHeaderNav:(RecreationViewModel *)model
{
    HNRecreationViewController *HNRecreationVC = [[HNRecreationViewController alloc]init];
    
    HNRecreationVC.model = model;
    
    [self.navigationController pushViewController:HNRecreationVC animated:YES];
    
}

//  军事   实现代理方法
- (void)addWarNav:(RecreationViewModel *)model
{
    HNWarHeaderViewController *HNWarHeader = [[HNWarHeaderViewController alloc]init];
    HNWarHeader.model = model;
    
    [self.navigationController pushViewController:HNWarHeader animated:YES];
}
// 历史  实现代理方法
- (void)addHistory:(RecreationViewModel *)model
{
    HNHistoryHeaderViewController *HNHistoryHeader = [[HNHistoryHeaderViewController alloc]init];
    
    HNHistoryHeader.model = model;
    
    [self.navigationController pushViewController:HNHistoryHeader animated:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
